package com.example.common.config.common.session;

import com.example.common.constant.AuthServerConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * <p>
 *      spring session 存储redis序列化配置
 *      放入到 cookie 的配置
 * </p>
 *
 * @author zyred
 * @since v 0.1
 **/
@Slf4j
@Configuration
public class GuliMallSessionConfig {

    @Bean
    public CookieSerializer cookieSerializer () {
        log.info(">>>>>>>>>>>>>>>> common session init start >>>>>>>>>>>>>>>>>>>>>");
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        serializer.setCookieName(AuthServerConstant.GULI_MALL_SESSION_ID);
        serializer.setDomainName("gulimall.com");
        log.info("<<<<<<<<<<<<<<<< common session init end <<<<<<<<<<<<<<<<<<<<");
        return serializer;
    }

    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer () {
        return new GenericJackson2JsonRedisSerializer();
    }
}
